package com.ruoyi.web.controller.ToolController;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.web.controller.common.UrlCommon;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;

@Api(tags = "娱乐相关")
@ResponseBody
@RestController
@RequestMapping("/tool/interest")
public class InterestController extends BaseController {

    @GetMapping("/tiangou")
    @ApiOperation("舔狗日记")
    public R<String> videoRemoveWatermark() {
        return R.ok(HttpUtil.get(UrlCommon.TIAN_GOU));
    }

    @GetMapping("/kfc4")
    @ApiOperation("肯德基疯狂星期四文案获取")
    public R<String> kfc4() {
        String s = HttpUtil.get(UrlCommon.KFC4);
        String text = JSONObject.parseObject(s).get("text").toString();
        return R.ok(text);
    }

    @GetMapping("/wangyiyun")
    @ApiOperation("网易云热评")
    public R<String> wangyiyunreping() {
        return R.ok(HttpUtil.get(UrlCommon.WANG_YI_YUN_REPING + "?aa1=json"));
    }

    @GetMapping("/naowan")
    @ApiOperation("脑筋急转弯查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "num", value = "返回数量")
    })
    public R naowan(@RequestParam String num) {
        String path = "?num=" + num;
        String s = HttpUtil.get(UrlCommon.DM_NAOWAN + path);
        if (UrlCommon.isCode(s)) {
            Object o = JSONObject.parseObject(JSONObject.parseObject(s).get("data").toString());
            return R.ok(o.toString());
        } else {
            return R.fail("查询失败!");
        }
    }

    @GetMapping("/dog/text")
    @ApiOperation("狗屁不通文章生成")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "msg", value = "内容")
    })
    public R dogText(@RequestParam String msg) {
        String path = "?msg=" + msg;
        String s = HttpUtil.get(UrlCommon.DOG_TEXT + path);
        Object o = JSONObject.parseObject(s).get("data").toString();
        return R.ok(o.toString());
    }

    @GetMapping("/piao")
    @ApiOperation("电影票房前 10 查询")
    //接口地址 https://api.aa1.cn/doc/dypf.html
    public R qrcode() {
        return R.ok(HttpUtil.get(UrlCommon.PIAO));
    }

    @GetMapping("/yan/zhi")
    @ApiOperation("颜值打分")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "url", value = "连接地址")
    })
    //接口地址 https://api.lolimi.cn/?action=doc&id=138
    public R yanZhi(@RequestParam String url) {
        String path = "?url="+url;
        return R.ok(HttpUtil.get(UrlCommon.YAN_ZHI+path));
    }

    @GetMapping("/apidhw")
    @ApiOperation("土味情话")
    //地址 https://api.aa1.cn/doc/qh-apidhw.html
    public R apidhw() {
        return R.ok(HttpUtil.get(UrlCommon.APIDHW));
    }

    @GetMapping("/alipay/yy")
    @ApiOperation("支付宝到账语音")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "money", value = "金额")
    })
    //地址 https://api.aa1.cn/doc/wqwlkj_aliyy.html
    public R alipayYy(@RequestParam String money) {
        String path = "?money="+money;
        return R.ok(HttpUtil.get(UrlCommon.ALIPAY_YY+path));
    }

}
